package com.droidwatcher.variables;

import com.alibaba.fastjson.JSON;
import com.droidwatcher.JsonEntity.HttpRequestHead;
import com.droidwatcher.JsonEntity.LocationEntityInfo;
import com.droidwatcher.JsonEntity.LocationJsonObj;
import com.droidwatcher.lib.GDGPS;
import com.droidwatcher.lib.GPS;
import com.droidwatcher.lib.MessageType;

import java.util.Map;

/**
 * Created by Administrator on 2018/1/24.
 */

public class LocationServerMsg implements IServerMessage {
    public MessageType type;

    private Map<String, Object> map;

    GPS gps ;



    @Override
    public MessageType getType() {
            return type;
    }

    public LocationServerMsg(MessageType type, GPS gps){
        this.type = type ;
        this.gps = gps;
    }

    public LocationServerMsg addParam(String key, Object value) {
        map.put(key, value);
        return this;
    }

    @Override
    public String getJSONString() {
        LocationJsonObj obj = new LocationJsonObj() ;
        obj.setHead(new HttpRequestHead());
        LocationEntityInfo info = new LocationEntityInfo() ;
        if(gps instanceof GDGPS){
            info.setLatitude(((GDGPS) gps).lat);
            info.setLongitude(((GDGPS) gps).lon);
            info.setPower(((GDGPS) gps).battery);
            info.setLocation(((GDGPS) gps).location);
            info.setUpdate_time(String.valueOf(((GDGPS) gps).date));
            obj.setInfo(info);
        }else if(gps instanceof GPS){
             info.setLatitude(gps.lat);
             info.setLongitude(gps.lon);
             info.setPower(gps.battery);
             info.setLocation("深圳市南山区科兴科技园中兴大厦");
             info.setUpdate_time(String.valueOf(gps.date));
             obj.setInfo(info);
         }
        return JSON.toJSONString(obj);

    }

//    public void getDataFromDH(final String parameters){
//
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    AXLog.e("wzytest","getDataFromDH  parameters:"+parameters);
//                    String apiURL = "http://sp.kuuvv.com/api/user/signup";
//                    HttpClient httpClient = new DefaultHttpClient();
//                    HttpPost post = new HttpPost(apiURL);
//                    post.addHeader("Content-type","application/json; charset=utf-8");
//                    post.setHeader("Accept", "application/json");
//                    try {
//                        post.setEntity(new StringEntity(parameters, "UTF-8"));
//                        HttpResponse response = httpClient.execute(post);
//                        int statusCode = response.getStatusLine().getStatusCode();
//                        if (statusCode != HttpStatus.SC_OK) {
//                            AXLog.e("wzytest" , "response.getStatusLine()" + response.getStatusLine());
//                        }
//                        String body = EntityUtils.toString(response.getEntity());
//
//                        AXLog.e("wzytest","getDataFromDH statusCode:"+statusCode +" body:"+body);
//                    } catch (UnsupportedEncodingException e) {
//                        e.printStackTrace();
//                    } catch (ClientProtocolException e) {
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//
//                }
//            }).start();
//    }

}
